<?php
// +----------------------------------------------------------------------
// | Description: 客户
// +----------------------------------------------------------------------
// | Author: zl
// +----------------------------------------------------------------------

namespace app\crm\controller;

use app\admin\controller\ApiCommon;
use app\crm\model\BalanceLog;
use app\crm\model\Setting;
use app\crm\model\SettingCategory;
use app\crm\model\Service;
use app\crm\model\ReturnVist;
use app\crm\model\ReturnVistT;
use app\crm\model\Customer as CustomerModel;
use app\crm\model\TransferShop;
use app\crm\model\CustomerConfig as CustomerConfigModel;
use app\crm\model\CustomerGrade as CustomerGradeModel;
use think\response\Json;
use think\facade\Db;

class Kfdsvist extends ApiCommon
{
    /**
     * 用于判断权限
     * @permission 无限制
     * @allow 登录用户可访问
     * @other 其他根据系统设置
     **/
    public function initialize()
    {
        $action = [
            'permission' => [],
            'allow' => []
        ];
        event('CheckAuth',$action);
        $request = $this->request;
        $a = strtolower($request->action());

        $this->customerModel = new CustomerModel();
        $this->customerConfigModel = new CustomerConfigModel();
        if (!in_array($a, $action['permission'])) {
            parent::initialize();
        }
    }
    public function index(ReturnVist $ReturnVist): Json
     {
         $shopIds = $this->getCommonShopIdsCollectByUserType();
        $this->param['shopIds'] = $shopIds;
        $this->param['userInfo'] = $this->userInfo;

        $data = $ReturnVist->getList($this->param);
        // if (!$data) {
        //     return resultArray(['error' => $ReturnVist->getError()]);
        // }
        return resultArray(['data' => $data]);
     }
     
    public function addDs(ReturnVist $ReturnVist): Json
    {
        $this->param['userInfo'] = $this->userInfo;
        $this->param['user_id'] = $this->userInfo['id'];
        $data = $ReturnVist->addDs($this->param);
        if (!$data) {
            return resultArray(['error' => $ReturnVist->getError()]);
        }
        return resultArray(['data' => $data,'error' => $ReturnVist->getError()]);
    }
    
    public function  addDsXh(ReturnVist $ReturnVist): Json
    {
        $this->param['userInfo'] = $this->userInfo;
        $this->param['user_id'] = $this->userInfo['id'];
        $data = $ReturnVist->addDsXh($this->param);
        if (!$data) {
            return resultArray(['error' => $ReturnVist->getError()]);
        }
        return resultArray(['data' => $data,'error' => $ReturnVist->getError()]);
    }
}
